@echo off
chcp 65001 >nul
echo ==========================================
echo OCR日期提取和文件重命名工具
echo ==========================================

echo.
echo [1/3] 设置Tesseract OCR环境...
set "Path=%~dp0lib\Tesseract-OCR;%Path%"
where tesseract >nul 2>nul
if %errorlevel% neq 0 (
    echo 错误: 未找到Tesseract OCR，请确保已安装并添加到PATH环境变量
    echo.
    echo 安装方法:
    echo 1. 下载Tesseract: https://github.com/UB-Mannheim/tesseract/wiki
    echo 2. 安装到默认目录: C:\Program Files\Tesseract-OCR\
    echo 3. 添加环境变量: C:\Program Files\Tesseract-OCR\ 到PATH
    echo 4. 下载中文语言包: chi_sim.traineddata
    echo.
    pause
    exit /b 1
) else (
    echo ✓ Tesseract OCR已找到
)
 
echo.
echo [2/3] 设置Tesseract环境变量...
set "TESSDATA_PREFIX=%~dp0lib\Tesseract-OCR\tessdata"
if not exist "%TESSDATA_PREFIX%" (
    set "TESSDATA_PREFIX=%ProgramFiles%\Tesseract-OCR\tessdata"
    if not exist "%TESSDATA_PREFIX%" (
        set "TESSDATA_PREFIX=%ProgramFiles(x86)%\Tesseract-OCR\tessdata"
    )
)
echo TESSDATA_PREFIX=%TESSDATA_PREFIX%

@REM echo.
@REM echo [3/5] 安装Go依赖...
@REM go mod tidy
@REM if %errorlevel% neq 0 (
@REM     echo 错误: Go依赖安装失败
@REM     pause
@REM     exit /b 1
@REM )

@REM echo.
@REM echo [4/5] 编译程序...
@REM go build -o ocr-date-extract-new.exe
@REM if %errorlevel% neq 0 (
@REM     echo 错误: 程序编译失败
@REM     pause
@REM     exit /b 1
@REM )
@REM echo ✓ 编译成功

echo.
echo [3/3] 运行OCR日期提取程序...
echo 使用默认设置: 处理images目录，4个并发线程
echo 按Ctrl+C可随时停止程序
echo.
ocr-date-extract-new.exe -jobs 4

echo.
echo 程序执行完成！
pause
